<template>
  <div class="worthBuy">
    <HeaderTitle></HeaderTitle>
    <div class="header">
      <img class="worth" src="https://yanxuan.nosdn.127.net/0b7676e645253f84be662aacfc051922.png" alt="">
      <div class="text">严选好物 用心生活</div>
      <div class="list">
        <van-swipe class="swiper" :loop="false" :width="90" @change="onChange" ref="swiper">
          <van-swipe-item v-for="(nav, index) in navList1" :key="nav.id">
            <div class="navList">
              <div class="navItem" @click="toDevelopingPage">
                <img class="navImg" :src="nav.picUrl" alt="">
                <div class="navTitle">{{ nav.mainTitle }}</div>
                <div class="navDesc">{{ nav.viceTitle }}</div>
              </div>
              <div class="navItem" @click="toDevelopingPage">
                <img class="navImg" :src="navList2[index].picUrl" alt="">
                <div class="navTitle">{{ navList2[index].mainTitle }}</div>
                <div class="navDesc">{{ navList2[index].viceTitle }}</div>
              </div>
            </div>
          </van-swipe-item>
        </van-swipe>
      </div>
    </div>
    <div class="scroll">
      <div class="scrollItem">
        <div class="item">
          <div class="one" v-for="item in ItemLeft" :key="item.topicId"  @click="toDevelopingPage">
            <img class="primaryImg" :src="item.picUrl" alt="">
            <div class="title">{{ item.subTitle }}</div>
            <div class="desc">
              <img class="headImg" :src="item.avatar" alt="">
              <div class="name">{{ item.nickname }}</div>
              <img class="watch" src="https://yanxuan.nosdn.127.net/5097bc5f2e1eb15f2a32b56895db073a.png" alt="">
              <div class="total">{{ item.readCount }}K</div>
            </div>
          </div>
        </div>
        <div class="item">
          <div class="one" v-for="item in ItemRight" :key="item.topicId"  @click="toDevelopingPage">
            <img class="primaryImg" :src="item.picUrl" alt="">
            <div class="title">{{ item.subTitle }}</div>
            <div class="desc">
              <img class="headImg" :src="item.avatar" alt="">
              <div class="name">{{ item.nickname }}</div>
              <img class="watch" src="https://yanxuan.nosdn.127.net/5097bc5f2e1eb15f2a32b56895db073a.png" alt="">
              <div class="total">{{ item.readCount }}K</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <Tabbar></Tabbar>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue"
export default defineComponent({
  name: 'WorthBuy',
})
</script>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import HeaderTitle from '@/components/HeaderTitle/index.vue'
import Tabbar from '@/components/Tabbar/index.vue'
import useWorthBuyStore from '@/stores/moduls/worthBuy'
import { storeToRefs } from 'pinia'
import { useRouter } from 'vue-router'

// 控制轮播下面的小线段跟随轮播动
const swiper = ref()
function onChange(index: number) {
  if (index === 4) {
    swiper.value.swipeTo(3)
  }
}

const worthBuyStore = useWorthBuyStore()
let { navList1, navList2, ItemLeft, ItemRight } = storeToRefs(worthBuyStore)

onMounted(() => {
  // 获取值得买页面轮播数据
  worthBuyStore.getWorthBuyBannerList()
  // 获取下面瀑布流的数据
  worthBuyStore.getWorthBuyItemList()
})

const router = useRouter()
function toDevelopingPage() {
  router.push('/developing')
}





</script>

<style lang="less" scoped>
.worthBuy {
  background-color: #eee;

  .header {
    width: 375px;
    height: 270px;
    margin-top: 50px;
    padding: 72.5px 0 0;
    background-image: url('https://yanxuan.nosdn.127.net/a93a392fb8006ba26dea38477979b7b4.jpg?imageView');
    background-size: 375px 259px;
    background-repeat: no-repeat;
    position: relative;

    .worth {
      position: absolute;
      top: 30px;
      left: 6px;
      width: 65px !important;
      height: 34.5px !important;
    }

    .text {
      position: absolute;
      top: 40px;
      left: 73px;
      font-size: 15px;
      color: #fff;
      font-weight: 500;
    }

    .list {
      width: 355px;
      height: 270px;
      position: relative;
      background-color: #fff;
      margin: 0 auto;
      border-radius: 7px;

      .swiper {
        width: 355px;
        height: 270px;

        .navList {
          width: 90px;
          display: flex;
          flex-direction: column;
          align-items: center;

          .navItem {
            margin-top: 18px;
            display: flex;
            flex-direction: column;
            align-items: center;

            .navImg {
              width: 60px;
              height: 60px;
            }

            .navTitle {
              font-size: 14px;
              font-weight: bold;
              color: #333;
            }

            .navDesc {
              font-size: 12px;
              color: #999;
              margin: 1px 0 0;
            }
          }
        }
      }

      .scrollPro {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        bottom: 10px;
        display: flex;

        .proItem {
          width: 19.5px;
          height: 2px;
          background-color: #d9d9d9;

          &.active {
            background-color: #dd1a21;
          }
        }
      }
    }

    ::v-deep(.van-swipe__indicator:nth-last-child(1)) {
      display: none;
    }

    ::v-deep(.van-swipe__indicator:nth-last-child(2)) {
      display: none;
    }

    ::v-deep(.van-swipe__indicator:nth-last-child(3)) {
      display: none;
    }

    ::v-deep(.van-swipe__indicator) {
      width: 20px;
      height: 2px;
      border-radius: 0;
    }

    ::v-deep(.van-swipe__indicator--active) {
      background-color: #dd1a21;
    }

  }

  .scroll {
    padding: 15px 10px 50px 10px;

    .scrollItem {
      display: flex;

      .item {
        display: flex;
        flex-direction: column;
        margin-right: 10px;

        .one {
          background-color: #fff;
          border-radius: 10px;
          margin-bottom: 10px;
        }

        .primaryImg {
          width: 172.5px;
          border-radius: 10px 10px 0 0;
        }

        .title {
          width: 155.5px;
          line-height: 20px;
          padding: 9px 8px 8.5px 8px;
          font-size: 14px;
          font-weight: 500;
        }

        .desc {
          display: flex;
          align-items: center;
          width: 155.5px;
          height: 24px;
          padding: 8.5px 8px 12px;
          font-size: 12px;
          color: #7f7f7f;

          .headImg {
            width: 24px;
            height: 24px;
            border-radius: 50%;
            margin-right: 4px;
          }

          .name {
            flex: 1;
          }

          .watch {
            width: 16px;
            height: 16px;
          }
        }
      }
    }
  }
}
</style>